<?php
session_start();
require_once( 'configs/config.php' );
require_once( 'lib/db.php' );
require_once( 'lib/functions.php' );
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();

if( (isset( $_SESSION[ 'UID' ] ) && $_GET[ 'id' ] == $_SESSION[ 'UID' ] ) || $_SESSION[ 'Level' ] == $config[ 'Admin' ] )
{
	$smarty->assign('logged_in', 'true');
	$smarty->assign('admin', 'true');
	$smarty->assign('self', 'true');
}
else
{
	header( 'Location: login.php' );
	exit;
}

$dbUsers = $db->get_results( 'SELECT u.UserUID, CONCAT(u.FirstName, \' \', u.LastName) as Name, u.Gender, u.Email, u.PhoneNumber, count(p.UserUID) as Payments, g.Name as GroupName FROM users u, payments p, usergroups g WHERE u.UserUID=p.UserUID AND u.GroupUID=g.GroupUID GROUP BY p.UserUID ORDER BY u.UserUID DESC LIMIT 10' );
//$db->debug();

for($i = 0; $i < count($dbUsers); $i++)
{
	foreach($dbUsers[$i] as $key => $value)
	{
		if( $key == 'PhoneNumber' )
		{
			$users[$i][strtolower($key)] = ereg_replace ('[^0-9]+', '', $value);
		}
		else
		{
			$users[$i][strtolower($key)] = $value;
		}
	}
}

$smarty->assign('title', 'Add An Account');
$smarty->assign('users', $users);
$smarty->assign('form', 'addAccountProcess.php');
$smarty->display('addAccount.tpl');
?>
